package co.udea.ingweb.hibernate.dao.impl;

import java.util.ArrayList;
import java.util.List;
import org.apache.log4j.Logger;
import org.hibernate.HibernateException;
import org.hibernate.Session;
import co.udea.ingweb.hibernate.dao.DAOAlerta;
import co.udea.ingweb.hibernate.dao.HibernateUtil;
import co.udea.ingweb.hibernate.model.Alerta;

/***
 * 
 * @author FARLEY RUA - CARLOS MARIO BEDOYA
 * @version 1.0
 * 
 * Clase que implementa los metodos de la interfaz DAOAlerta
 * @see DAOAlerta
 *
 */
public class DAOAlertaImpl implements DAOAlerta {

        private static Logger logger = Logger.getLogger(DAOAlertaImpl.class);
        
        @Override
        public List<Alerta> listarAlertas() {
                Session session = HibernateUtil.getSessionFactory().openSession(); 
                List<Alerta> encontrados = new ArrayList<Alerta>();
                
                try{
                        encontrados = session.createQuery("from alerta").list();
                } 
                catch (HibernateException ex){
                        logger.debug("Error" + ex.getLocalizedMessage());
                } 
                finally{
                        session.close();
                }
                
                return encontrados;
        }
}